package com.cloud.basic.lambda.usage;

import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * @program: basic
 * @description:
 * @author: Cloud
 * @create: 2022-08-05 15:43
 **/
public class testConsumer {

    public static void main(String[] args) {
        Consumer<PersonOne> greeter = (p) -> System.out.println("Hello, " + p.getName());
        greeter.accept(new PersonOne("Luke", "Skywalker",5));

        Supplier<PersonOne> personSupplier = PersonOne::new;
        System.out.println("personSupplier.get() = " + personSupplier.get());


        Predicate<String> predicate = (s) -> s.length() > 0;

        predicate.test("foo");              // true
        predicate.negate().test("foo");     // false

        Predicate<Boolean> nonNull = Objects::nonNull;
        Predicate<Boolean> isNull = Objects::isNull;

        Predicate<String> isEmpty = String::isEmpty;
        Predicate<String> isNotEmpty = isEmpty.negate();

        Function<String, Integer> toInteger = Integer::valueOf;
        Function<String, String> backToString = toInteger.andThen(String::valueOf);

        backToString.apply("123");     // "123"

    }
}
